package com.hxs.hxsserver.domain.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @description: 返回结果包装
 * @author: Andi
 * @create: 2020-07-14 15:39
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class JsonResult<T> implements Serializable {
    private static final long serialVersionUID = 1L;

    private int code;

    private T data;

    private String msg;

    public JsonResult(T data) {
        this.code = ResponseCode.SUCCESS.getCode();
        this.data = data;
    }

    public JsonResult(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public JsonResult(T data, int code, String msg) {
        this.data = data;
        this.code = code;
        this.msg = msg;
    }


    public static JsonResult success(Object data) {
        return new JsonResult(data);
    }

    public static JsonResult success(Object data, String msg) {
        return new JsonResult(data, ResponseCode.SUCCESS.getCode(), msg);
    }

    public static JsonResult fail(int code, String msg) {
        return new JsonResult(code, msg);
    }

    public static JsonResult fail(Object data, int code, String msg) {
        return new JsonResult(data, code, msg);
    }
}
